<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>岚山一中一卡通</title>
    <link rel="stylesheet" href="/css/weui.min.css"/>
    <link rel="stylesheet" href="/css/myWxmp.css"/>
</head>
<body ontouchstart>
<div class="container" id="container">
    <div class="page js_show">
        <div class="page__hd">
            <h1 class="page__title" id="recharge_amount"></h1>
        </div>
        <div class="page__bd">
            <div class="weui-form-preview">
                <div class="weui-form-preview__bd">
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">商品</label>
                        <span class="weui-form-preview__value">一卡通充值</span>
                    </div>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">收款人</label>
                        <span class="weui-form-preview__value">岚山一中</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="weui-msg__extra-area">
            <div class="weui-footer">
                <p class="weui-footer__text">Copyright &copy; 2018-2019</p>
            </div>
        </div>
    </div>
</div>
<script src="/js/zepto.min.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
<script type="text/javascript">
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)
            return decodeURI(r[2]);
        return null;
    }

    var payAmount = GetQueryString('amount');
    payAmount = payAmount / 100;
    $("#recharge_amount").html(payAmount);

    var myAppId = GetQueryString('appId');
    var myTimeStamp = GetQueryString('timeStamp');
    var myNonceStr = GetQueryString('nonceStr');
    var myPackage = GetQueryString('package');
    var mySignType = GetQueryString('signType');
    var myPaySign = GetQueryString('paySign');

    function onBridgeReady(payParams) {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
                "appId": myAppId,
                "timeStamp": myTimeStamp,
                "nonceStr": myNonceStr,
                "package": myPackage,
                "signType": mySignType,
                "paySign": myPaySign
            },
            function (res) {
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    window.location.href = "rechargeSuccess.html";
                } else {
                    showFailure('支付失败');
                }
                WeixinJSBridge.call('closeWindow');
            }
        );
    }

    function showFailure(msg) {
        window.location.href = 'failure.html?failTip=' + encodeURIComponent(msg);
    }

    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    } else {
        onBridgeReady();
    }
</script>
</body>
</html>
